﻿Imports System.Data.SQLite
Imports System.ComponentModel

Public Class Watch

    Implements INotifyPropertyChanged

    Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

    Private Const IDXCOL_ID = 0
    Private Const IDXCOL_REFERENCE = 1
    Private Const IDXCOL_NAME = 2
    Private Const IDXCOL_REFBRAND = 3

    Private _Id As Byte()
    Private _Reference As String
    Private _Name As String
    Private _RefBrand As Byte()

    Public Property Id As Byte()
        Get
            Return Id
        End Get
        Set(value As Byte())
            Array.Copy(value, _Id, DBContext.ID_LENGTH)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Id"))
        End Set
    End Property

    Public Property Reference As String
        Get
            Return _Reference
        End Get
        Set(value As String)
            _Reference = value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Reference"))
        End Set
    End Property

    Public Property Name As String
        Get
            Return _Name
        End Get
        Set(value As String)
            _Name = value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Name"))
        End Set
    End Property

    Public Property RefBrand As Byte()
        Get
            Return _RefBrand
        End Get
        Set(value As Byte())
            Array.Copy(value, _RefBrand, DBContext.ID_LENGTH)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("RefBrand"))
        End Set
    End Property

    Public Sub New(dr As SQLiteDataReader)
        dr.GetBytes(IDXCOL_ID, 0, Id, 0, DBContext.ID_LENGTH)
        dr.GetBytes(IDXCOL_REFBRAND, 0, RefBrand, 0, DBContext.ID_LENGTH)
        Reference = dr.GetString(IDXCOL_REFERENCE)
        Name = dr.GetString(IDXCOL_NAME)
    End Sub


End Class
